From 4440e29b50c17a8ddb29af163cf9045d75216828 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 10 Nov 2005 15:16:01 +0100 Subject: [PATCH] Indirect writes to phys_to_machine_mapping array through an inline function defined in page.h. For self-migration, I need the ability to trap writes to the p2m map during migration, because I keep a dictionary mapping mfns to pfns, which I use for remapping the page tables once I am on the other side. Signed-off-by: Jacob Gorm Hansen --- linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c | 14 +++++++------- linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c | 7 +++---- linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c | 6 +++--- linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c | 4 ++-- linux-2.6-xen-sparse/drivers/xen/netback/netback.c | 9 ++++----- .../drivers/xen/netfront/netfront.c | 5 ++--- linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c | 5 ++--- .../include/asm-xen/asm-i386/page.h | 5 +++++ .../include/asm-xen/asm-x86_64/page.h | 5 +++++ 9 files changed, 33 insertions(+), 27 deletions(-) diff --git a/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c b/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c index a48ff231d0..9c8129be20 100644 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c @@ -342,8 +342,8 @@ int xen_create_contiguous_region( mfn = pte_mfn(*pte); BUG_ON(HYPERVISOR_update_va_mapping( vstart + (i*PAGE_SIZE), __pte_ma(0), 0)); - phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = - INVALID_P2M_ENTRY; + set_phys_to_machine((__pa(vstart)>>PAGE_SHIFT)+i, + INVALID_P2M_ENTRY); BUG_ON(HYPERVISOR_memory_op( XENMEM_decrease_reservation, &reservation) != 1); } @@ -361,7 +361,7 @@ int xen_create_contiguous_region( vstart + (i*PAGE_SIZE), pfn_pte_ma(mfn+i, PAGE_KERNEL), 0)); xen_machphys_update(mfn+i, (__pa(vstart)>>PAGE_SHIFT)+i); - phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = mfn+i; + set_phys_to_machine((__pa(vstart)>>PAGE_SHIFT)+i, mfn+i); } flush_tlb_all(); @@ -383,7 +383,7 @@ int xen_create_contiguous_region( vstart + (i*PAGE_SIZE), pfn_pte_ma(mfn, PAGE_KERNEL), 0)); xen_machphys_update(mfn, (__pa(vstart)>>PAGE_SHIFT)+i); - phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = mfn; + set_phys_to_machine((__pa(vstart)>>PAGE_SHIFT)+i, mfn); } flush_tlb_all(); @@ -422,8 +422,8 @@ void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order) mfn = pte_mfn(*pte); BUG_ON(HYPERVISOR_update_va_mapping( vstart + (i*PAGE_SIZE), __pte_ma(0), 0)); - phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = - INVALID_P2M_ENTRY; + set_phys_to_machine((__pa(vstart)>>PAGE_SHIFT)+i, + INVALID_P2M_ENTRY); BUG_ON(HYPERVISOR_memory_op( XENMEM_decrease_reservation, &reservation) != 1); } @@ -436,7 +436,7 @@ void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order) vstart + (i*PAGE_SIZE), pfn_pte_ma(mfn, PAGE_KERNEL), 0)); xen_machphys_update(mfn, (__pa(vstart)>>PAGE_SHIFT)+i); - phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = mfn; + set_phys_to_machine((__pa(vstart)>>PAGE_SHIFT)+i, mfn); } flush_tlb_all(); diff --git a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c index e501403e92..1c610a48df 100644 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c @@ -210,7 +210,7 @@ static int increase_reservation(unsigned long nr_pages) BUG_ON(phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY); /* Update P->M and M->P tables. */ - phys_to_machine_mapping[pfn] = mfn_list[i]; + set_phys_to_machine(pfn, mfn_list[i]); xen_machphys_update(mfn_list[i], pfn); /* Link back into the page tables if not highmem. */ @@ -295,7 +295,7 @@ static int decrease_reservation(unsigned long nr_pages) /* No more mappings: invalidate P2M and add to balloon. */ for (i = 0; i < nr_pages; i++) { pfn = mfn_to_pfn(mfn_list[i]); - phys_to_machine_mapping[pfn] = INVALID_P2M_ENTRY; + set_phys_to_machine(pfn, INVALID_P2M_ENTRY); balloon_append(pfn_to_page(pfn)); } @@ -515,8 +515,7 @@ static int dealloc_pte_fn( .domid = DOMID_SELF }; set_pte_at(&init_mm, addr, pte, __pte_ma(0)); - phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] = - INVALID_P2M_ENTRY; + set_phys_to_machine(__pa(addr) >> PAGE_SHIFT, INVALID_P2M_ENTRY); ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation); BUG_ON(ret != 1); return 0; diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c index a88d897332..a179690a0b 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c @@ -386,9 +386,9 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) #ifdef __ia64__ MMAP_VADDR(pending_idx,i) = gnttab_map_vaddr(map[i]); #else - phys_to_machine_mapping[__pa(MMAP_VADDR( - pending_idx, i)) >> PAGE_SHIFT] = - FOREIGN_FRAME(map[i].dev_bus_addr>>PAGE_SHIFT); + set_phys_to_machine(__pa(MMAP_VADDR( + pending_idx, i)) >> PAGE_SHIFT, + FOREIGN_FRAME(map[i].dev_bus_addr>>PAGE_SHIFT)); #endif fas = req->frame_and_sects[i]; seg[i].buf = map[i].dev_bus_addr | diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c index 03a4fcb970..6da3c62356 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c @@ -777,8 +777,8 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) /* Set the necessary mappings in p2m and in the VM_FOREIGN * vm_area_struct to allow user vaddr -> struct page lookups * to work. This is needed for direct IO to foreign pages. */ - phys_to_machine_mapping[__pa(kvaddr) >> PAGE_SHIFT] = - FOREIGN_FRAME(map[i].dev_bus_addr >> PAGE_SHIFT); + set_phys_to_machine(__pa(kvaddr) >> PAGE_SHIFT, + FOREIGN_FRAME(map[i].dev_bus_addr >> PAGE_SHIFT)); offset = (uvaddr - blktap_vma->vm_start) >> PAGE_SHIFT; ((struct page **)blktap_vma->vm_private_data)[offset] = diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c index c676672259..1d185e5059 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c @@ -248,8 +248,7 @@ static void net_rx_action(unsigned long unused) * Set the new P2M table entry before reassigning the old data * page. Heed the comment in pgtable-2level.h:pte_page(). :-) */ - phys_to_machine_mapping[__pa(skb->data) >> PAGE_SHIFT] = - new_mfn; + set_phys_to_machine(__pa(skb->data) >> PAGE_SHIFT, new_mfn); MULTI_update_va_mapping(mcl, vdata, pfn_pte_ma(new_mfn, PAGE_KERNEL), 0); @@ -631,9 +630,9 @@ static void net_tx_action(unsigned long unused) pending_idx; continue; } - phys_to_machine_mapping[ - __pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT] = - FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT); + set_phys_to_machine( + __pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT, + FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT)); grant_tx_ref[pending_idx] = mop->handle; data_len = (txreq.size > PKT_PROT_LEN) ? diff --git a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c index 24baa6e54d..33d6464f27 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c @@ -342,8 +342,7 @@ static void network_alloc_rx_buffers(struct net_device *dev) rx_pfn_array[i] = virt_to_mfn(skb->head); /* Remove this page from map before passing back to Xen. */ - phys_to_machine_mapping[__pa(skb->head) >> PAGE_SHIFT] - = INVALID_P2M_ENTRY; + set_phys_to_machine(__pa(skb->head) >> PAGE_SHIFT, INVALID_P2M_ENTRY); MULTI_update_va_mapping(rx_mcl+i, (unsigned long)skb->head, __pte(0), 0); @@ -570,7 +569,7 @@ static int netif_poll(struct net_device *dev, int *pbudget) pfn_pte_ma(mfn, PAGE_KERNEL), 0); mcl++; - phys_to_machine_mapping[__pa(skb->head) >> PAGE_SHIFT] = mfn; + set_phys_to_machine(__pa(skb->head) >> PAGE_SHIFT, mfn); __skb_queue_tail(&rxq, skb); } diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c index 9b02556e56..543c880560 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c @@ -296,9 +296,8 @@ _packet_write(struct packet *pak, DPRINTK(" Grant table operation failure !\n"); return 0; } - phys_to_machine_mapping[__pa(MMAP_VADDR(tpmif,i)) >> - PAGE_SHIFT] = - FOREIGN_FRAME(map_op.dev_bus_addr >> PAGE_SHIFT); + set_phys_to_machine(__pa(MMAP_VADDR(tpmif,i)) >> PAGE_SHIFT, + FOREIGN_FRAME(map_op.dev_bus_addr >> PAGE_SHIFT)); tocopy = MIN(size - offset, PAGE_SIZE); diff --git a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h index 098de998c0..4813c6a505 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h @@ -86,6 +86,11 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn) return pfn; } +static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn) +{ + phys_to_machine_mapping[pfn] = mfn; +} + /* Definitions for machine and pseudophysical addresses. */ #ifdef CONFIG_X86_PAE typedef unsigned long long paddr_t; diff --git a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h index 242d5b21ac..d454123723 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h @@ -88,6 +88,11 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn) return pfn; } +static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn) +{ + phys_to_machine_mapping[pfn] = mfn; +} + /* Definitions for machine and pseudophysical addresses. */ typedef unsigned long paddr_t; typedef unsigned long maddr_t; -- 2.30.2